# -*- coding: utf-8 -*-
import scrapy


class XtSpider(scrapy.Spider):
    name = 'xt'
    allowed_domains = ['ctrip.com',]
    start_urls = ['https://flights.ctrip.com/']

    def parse(self, response):
        div_list = response.xpath('//div[@class="searchresult_content"]/div[2]/div[2]/div/div[@class="search_box search_box_tag search_box_light Label_Flight"]')
        for div in div_list:
            item = {}
            item['airline'] = div.xpath('.//div[@class="inb logo"]/div[1]//text()').extract()
            item['airliner_type'] = div.xpath('.//div[@class="inb logo"]/div[2]//text()').extract_first()
            item['departure_time'] = div.xpath('.//div[@class="inb right"]/div/strong/text()').extract_first()
            item['departure_airport'] = div.xpath('.//div[@class="inb right"]/div[2]//text()').extract_first()
            item['time_of-arrival'] = div.xpath('.//div[@class="inb left"]/div/strong/text()').extract_first()
            item['destination_airport'] = div.xpath('.//div[@class="inb left"]/div[1]//text()').extract_first()
            item['price'] = div.xpath('.//div/div[7]/div/span//text()').extract()
            yield item
